package com.pro01.backend.mapper;

import com.pro01.backend.pojo.Forum;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ForumMapper {
    // 管理员创建板块
    @Insert("INSERT INTO forums (name, description, status, sort_order) VALUES (#{name}, #{description}, #{status}, #{sortOrder})")
    int insertForum(Forum forum); // ✅ 改为 int

    // 管理员查询板块
    @Select("SELECT * FROM forums WHERE status != 'DELETED' ORDER BY sort_order ASC, id ASC")
    List<Forum> selectAllForums();

    // 管理员删除板块
    @Update("UPDATE forums SET status = 'DELETED' WHERE id = #{id}")
    int softDeleteForum(Long id); // ✅ 改为 int

    // 管理员编辑板块
    @Update("""
        UPDATE forums
        SET name = #{name},
            description = #{description},
            status = #{status},
            sort_order = #{sortOrder}
        WHERE id = #{id}
    """)
    int updateForum(Forum forum); // ✅ 改为 int

    /**
     * 下面是所有用户的板块接口
     */

    // 用户查看所有板块信息
    @Select("SELECT * FROM forums WHERE status = 'ACTIVE' ORDER BY sort_order ASC, id ASC")
    List<Forum> selectVisibleForums();

}
